// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <llama.h>
#include <string>

namespace kllm {

    struct cpu_params {
        int n_threads = -1;
        bool cpumask[GGML_MAX_N_THREADS] = {false}; // CPU affinity mask.
        bool mask_valid = false;   // Default: any CPU
        enum ggml_sched_priority priority = GGML_SCHED_PRIO_NORMAL;  // Scheduling prio : (0 - normal, 1 - medium, 2 - high, 3 - realtime)
        bool strict_cpu = false;   // Use strict CPU placement
        uint32_t poll = 50;      // Polling (busywait) level (0 - no polling, 100 - mostly polling)
    };

    int32_t cpu_get_num_physical_cores();

    int32_t cpu_get_num_math();

    bool parse_cpu_range(const std::string &range, bool(&boolmask)[GGML_MAX_N_THREADS]);

    bool parse_cpu_mask(const std::string &mask, bool(&boolmask)[GGML_MAX_N_THREADS]);

    void postprocess_cpu_params(cpu_params &cpuparams, const cpu_params *role_model = nullptr);

    bool set_process_priority(enum ggml_sched_priority prio);

}  // namespace kllm
